package com.axsoft.jobimp.tests;

import com.axsoft.jobimp.OHeader;
import com.axsoft.jobimp.types.sTLD;
import com.axsoft.jobimp.types.wTLD;

/**
 * 
 * @author RankoR
 *
 * Test helpers
 */
public class OTestUtils {
	
	/**
	 * Check if arrays equals
	 */
	public static boolean byteArraysEquals(final byte[] pFirst, final byte[] pSecond) {
		if (pFirst.length != pSecond.length) {
			return false;
		}
		
		for (int i = 0; i < pFirst.length; i++) {
			if (pFirst[i] != pSecond[i]) {
				return false;
			}
		}
		
		return true;
	}
	
	
	/**
	 * Check if headers equals
	 */
	public static boolean headersEquals(final OHeader pFirst, final OHeader pSecond) {
		if (pFirst.mMark != pSecond.mMark) {
			return false;
		}
		
		if (pFirst.mSequence != pSecond.mSequence) {
			return false;
		}
		
		if (pFirst.mType != pSecond.mType) {
			return false;
		}
		
		if (pFirst.mSubType != pSecond.mSubType) {
			return false;
		}
		
		if (pFirst.mRequestId != pSecond.mRequestId) {
			return false;
		}
		
		if (pFirst.mLength != pSecond.mLength) {
			return false;
		}
		
		return true;
	}
	
	/**
	 * Check if wTLD equals
	 */
	public static boolean wTLDEquals(final wTLD pFirst, final wTLD pSecond) {
		if (pFirst.mType != pSecond.mType) {
			return false;
		}
		
		if (pFirst.mLength != pSecond.mLength) {
			return false;
		}
		
		return (byteArraysEquals(pFirst.mData.getData(), pSecond.mData.getData()));
	}
	
	/**
	 * Check if sTLD equals
	 */
	public static boolean sTLDEquals(final sTLD pFirst, final sTLD pSecond) {
		if (pFirst.mType != pSecond.mType) {
			return false;
		}
		
		if (pFirst.mLength != pSecond.mLength) {
			return false;
		}
		
		return (byteArraysEquals(pFirst.mData.getData(), pSecond.mData.getData()));
	}
	
}
